package yang.service.impl;

import org.apache.log4j.Logger;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import yang.dao.BaseDaoI;
import yang.model.HospitalMenu;
import yang.model.HospitalOffice;
import yang.model.HospitalUser;
import yang.service.RepairServiceI;

/**
 * 
 * @ClassName: RepairServiceImpl
 * @Description: 初始化服务
 * @author: Administrator
 * @date: 2014年6月21日 上午10:50:54
 */
@Service("repairService")
public class RepairServiceImpl implements RepairServiceI {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger
			.getLogger(RepairServiceImpl.class);
	private BaseDaoI<HospitalOffice> officeDao;
	private BaseDaoI<HospitalMenu> menuDao;
	private BaseDaoI<HospitalUser> userDao;

	public BaseDaoI<HospitalUser> geHospitalUserDao() {
		return userDao;
	}

	public BaseDaoI<HospitalOffice> getOfficeDao() {
		return officeDao;
	}

	@Autowired
	public void setOfficeDao(BaseDaoI<HospitalOffice> officeDao) {
		this.officeDao = officeDao;
	}

	@Autowired
	public void seHospitalUserDao(BaseDaoI<HospitalUser> userDao) {
		this.userDao = userDao;
	}

	public BaseDaoI<HospitalMenu> geHospitalMenuDao() {
		return menuDao;
	}

	@Autowired
	public void seHospitalMenuDao(BaseDaoI<HospitalMenu> menuDao) {
		this.menuDao = menuDao;
	}

	@Override
	synchronized public void repair() {

		repairOffice();

		repairUser();

		repairMenu();

	}

	/**
	 * 
	 * @Title: repairMenu
	 * @Description: 初始化菜单
	 * @return: void
	 */
	private void repairMenu() {
		HospitalMenu root = new HospitalMenu();
		root.setId("0");
		root.setText("首页");
		root.setUrl("");
		menuDao.saveOrUpdate(root);

		HospitalMenu ghgl = new HospitalMenu();
		ghgl.setId("ghgl");
		ghgl.setHospitalMenu(root);
		ghgl.setText("挂号管理");
		ghgl.setIconCls("server");
		ghgl.setUrl("/hospital/patientIndex.jsp");
		menuDao.saveOrUpdate(ghgl);

		HospitalMenu zlgl = new HospitalMenu();
		zlgl.setId("zlgl");
		zlgl.setHospitalMenu(root);
		zlgl.setText("治疗管理");
		zlgl.setIconCls("server");
		zlgl.setUrl("/hospital/doctorIndex.jsp");
		menuDao.saveOrUpdate(zlgl);

		HospitalMenu jfgl = new HospitalMenu();
		jfgl.setId("jfgl");
		jfgl.setHospitalMenu(root);
		jfgl.setText("缴费管理");
		jfgl.setIconCls("server");
		jfgl.setUrl("/hospital/jiaofeiIndex.jsp");
		menuDao.saveOrUpdate(jfgl);

		HospitalMenu yfgl = new HospitalMenu();
		yfgl.setId("yfgl");
		yfgl.setHospitalMenu(root);
		yfgl.setText("药房管理");
		yfgl.setIconCls("server");
		yfgl.setUrl("/hospital/drugIndex.jsp");
		menuDao.saveOrUpdate(yfgl);
		
		HospitalMenu yhgl=new HospitalMenu();
		yhgl.setId("yhgl");
		yhgl.setHospitalMenu(root);
		yhgl.setText("用户管理");
		yhgl.setIconCls("server");
		yhgl.setUrl("/user/saveUser.jsp");
		menuDao.saveOrUpdate(yhgl);
	}

	/**
	 * @Title: repairUser
	 * @Description:  初始化用户
	 * @return: void
	 */
	private void repairUser() {
		
		
		logger.info("初始账号:admin,密码:admin");
	}

	private void repairOffice() {
		HospitalOffice office = new HospitalOffice();
		office.setOfFunction("外科");
		office.setOfName("外科");
		office.setOfId(1);
		officeDao.saveOrUpdate(office);
		
		HospitalOffice office2 = new HospitalOffice();
		office2.setOfFunction("内科");
		office2.setOfName("内科");
		office2.setOfId(2);
		officeDao.saveOrUpdate(office2);
	}

}
